﻿using B.Z.BasicData.Domain.Entity.Authorize;
using B.Z.BasicData.ErrorCode;
using B.Z.BasicData.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.Z.BasicData.API.Read.Application.User
{
    public class ProvienceQueryCommandHandler : IRequestHandler<ProvienceQueryCommand, APIResult<List<T_Province>>>
    {
        private readonly IBaseRepository<T_Province> provinceRepository;

        public ProvienceQueryCommandHandler(IBaseRepository<T_Province> provinceRepository)
        {
            this.provinceRepository = provinceRepository;
        }

        public Task<APIResult<List<T_Province>>> Handle(ProvienceQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<T_Province>> result = new APIResult<List<T_Province>>();
            result.Code = APIEnum.ok;
            result.Message = "获取成功";
            var list = provinceRepository.GetAll().AsNoTracking().Where(p => !p.IsDelete);
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
